home *** CD-ROM | disk | FTP | other *** search
- Path: rcp6.elan.af.mil!rscernix!danpop
- From: danpop@mail.cern.ch (Dan Pop)
- Newsgroups: comp.lang.c
- Subject: Re: C constant expression declarations
- Date: 17 Feb 96 21:28:51 GMT
- Organization: CERN European Lab for Particle Physics
- Message-ID: <danpop.824592531@rscernix>
- References: <31229735.41C67EA6@isi.com> <4fvl5cINN94q@keats.ugrad.cs.ubc.ca> <4g2nha$ksa@sun001.spd.dsccc.com> <4g3fkeINNoj7@keats.ugrad.cs.ubc.ca>
- NNTP-Posting-Host: ues5.cern.ch
- X-Newsreader: NN version 6.5.0 #7 (NOV)
-
- In <4g3fkeINNoj7@keats.ugrad.cs.ubc.ca> c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku) writes:
-
- >Parentheses are intended to override operator precedence, and to occasionally
- >make a complex expression clearer to someone reading them; a proverbial icing
- >on the cake of sorts.
- >
- >if (x == 3 || y > 4 && z < 5)
- >
- >is easier to read than
- >
- >if ((x == 3) || ((y > 4) && (z < 5)))
-
- But
-
- if (x == 3 || (y > 4 && z < 5))
-
- is even easier to read. An expression with too many operators becomes
- difficult to read in the total absence of parentheses (especially if
- you don't have an operator precedence table handy :-) Unfortunately, the
- right amount of (otherwise) unnecessary parentheses needed to make a
- complex expression readable differs from person to person.
-
- Here's a very perfid trap, waiting to catch the unsuspecting programmer:
-
- if (a & mask == b)
-
- This is a known deficiency of the C operator precedence, deeply rooted
- in the history of the C language (once upon a time, & and && were only
- one operator).
-
- Just my $0.02,
- Dan
- --
- Dan Pop
- CERN, CN Division
- Email: danpop@mail.cern.ch
- Mail: CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
-